<template>
  <div class="app-container">
    <el-form :model="searchForm" :inline="true">
      <el-row>
        <el-col :span="12">
          <el-form-item label="样品编号:">
            <el-input v-model="searchForm.sampleNo" style="width:165px" placeholder="样品编号" />
          </el-form-item>
          <el-form-item label="样品状态:">
            <el-select v-model="searchForm.sampStatus" clearable filterable style="width:165px" placeholder="请选择状态">
              <el-option
                v-for="item in Object.keys(SAMPLE_STATUS)"
                :key="item"
                :label="SAMPLE_STATUS[item]"
                :value="item"
              />
            </el-select>
          </el-form-item>
          <el-form-item>
            <el-button type="primary" class="iconfont icon-chaxun1" @click="handleSearch"> 查询</el-button>
            <el-button type="primary" class="iconfont icon-fanhui" @click="goBack"> 返回</el-button>
          </el-form-item>
        </el-col>
<!--        <el-col :span="12" class="search-right">-->
<!--          <el-dropdown trigger="click" @command="handleCommand">-->
<!--            <span class="el-dropdown-link" style="color:#1890ff;margin-right:20px">-->
<!--              <i class="el-icon-plus" />新增质控样-->
<!--            </span>-->
<!--            <el-dropdown-menu slot="dropdown">-->
<!--              <el-dropdown-item command="新增平行样">平行样</el-dropdown-item>-->
<!--              <el-dropdown-item command="新增全程序空白样">全程序空白样</el-dropdown-item>-->
<!--              <el-dropdown-item command="新增运输空白样">运输空白样</el-dropdown-item>-->
<!--              <el-dropdown-item command="新增子样品">子样品</el-dropdown-item>-->
<!--              <el-dropdown-item command="新增密码样">密码样</el-dropdown-item>-->
<!--            </el-dropdown-menu>-->
<!--          </el-dropdown>-->

<!--          <el-button type="text" icon="el-icon-edit-outline" @click="handleAllEdit">批量修改</el-button>-->
<!--          <el-button type="text" icon="el-icon-circle-plus" @click="addGroup">新增样品</el-button>-->
<!--          <el-button type="text" icon="el-icon-upload2" @click="downloadTask">采样任务单导出</el-button>-->
<!--          <el-button type="text" icon="el-icon-upload" @click="handleAddRecords">采样记录单导出</el-button>-->
<!--          <el-button type="text" icon="el-icon-refresh" @click="handleSearch">刷新</el-button>-->
<!--        </el-col>-->
      </el-row>
    </el-form>
    <div>
      <el-table
        ref="mulTable"
        stripe
        border
        :data="sampleData"
        highlight-current-row
        :header-cell-style="{background:'#ECF3FC'}"
        style="width: 100%"
        @select-all="selectAll"
        @selection-change="handleSelectionChanges"
      >
        <template slot="empty">
          <div class="table_empty">
            <div class="empty_tips">
              <span>
                暂无采样样品信息
              </span>
            </div>
          </div>
        </template>
        <el-table-column
          type="selection"
          width="55"
          :selectable="checkboxSelect"
          fixed="left"
          align="center"
        />
        <el-table-column type="index" width="50" label="序号" fixed="left" align="center" />
        <el-table-column prop="sampleNo" label="样品编号" fixed="left" width="200px" align="center">
          <template slot-scope="{row}" style="position: relative;">
            <div v-if="row.sampleType == 0" style="padding: 0 3px;">{{ row.sampleNo }}</div>
            <div
              v-else
              class="codeInput"
              style="border:0px"
            >
              <el-input
                v-model.trim="row.sampleNo "
                type="text"
                style="background:transparent;"
                maxlength="15"
                @input="row.sampleNo = row.sampleNo.replace(/[\u4E00-\u9FA5]/g,'')"
                @change="updateSampleNo(row.sampItemId, row.sampleNo)"
              /></div>
            <div
              v-if="row.changeFlag == 1"
              style="position: absolute;
                top: -10px;
                right: -32px;
                background: #f91717;
                color: rgb(255, 255, 255);
                transform: rotate(45deg);
                font-size: 12px;
                padding: 13px 29px 0px;
                padding-bottom: 0;"
            >待删</div>
            <div
              v-if="row.changeFlag == 3"
              style="position: absolute;
                top: -10px;
                right: -32px;
                background: #fda827;
                color: rgb(255, 255, 255);
                transform: rotate(45deg);
                font-size: 12px;
                padding: 13px 29px 0px;
                padding-bottom: 0;"
            >待改</div>
            <div
              v-if="row.changeFlag == 2"
              style="position: absolute;
                top: -10px;
                right: -32px;
                background: #0c77ff;
                color: rgb(255, 255, 255);
                transform: rotate(45deg);
                font-size: 12px;
                padding: 13px 29px 0px;
                padding-bottom: 0;"
            >待增</div>
          </template>
        </el-table-column>

        <el-table-column prop="orginNo" label="原样品编号" width="180px" align="center" />
        <el-table-column prop="sampleType" width="130px" label="样品类别" align="center">
          <template slot-scope="{row}">
            <div v-if="row.sampleType == 0"> 标准样品</div>
            <div v-if="row.sampleType == 1">平行样</div>
            <div v-if="row.sampleType == 2"> 全程序空白样</div>
            <div v-if="row.sampleType == 3"> 输空白样</div>
            <div v-if="row.sampleType == 4">子样品</div>
            <div v-if="row.sampleType == 5">密码样</div>
          </template>
        </el-table-column>
        <el-table-column prop="inspectionName" width="140px" label="受检单位" align="center" />
        <el-table-column prop="factorPoint" width="130px" label="检测位置" align="center" />
        <el-table-column prop="secdClassName" label="检测类别" sortable width="130px" align="center" />
        <el-table-column prop="factorName" label="检测因子" width="180" align="center">
          <template slot-scope="row">
            <el-tooltip effect="dark" placement="top">
              <div slot="content" style="max-width: 400px">{{ row.row.factorName}}</div>
              <div class="apostrophe">
                <span>{{ row.row.factorName}}</span>
              </div>
            </el-tooltip>
          </template>
        </el-table-column>
        <el-table-column prop="collectTime" label="采样时间" align="center" width="190px">
          <template slot-scope="{row}">
            {{ row.collectTime&&row.collectTime.length>0?(row.collectDate + ' ' + row.collectTime):row.collectDate }}
          </template>
        </el-table-column>
        <!-- <el-table-column prop="sampleType" label="样品归类" width="120" align="center">
          <template slot-scope="{row}">
            <el-tag :type="row.sampleType ==='1'?'danger':''">
              {{ row.sampleType ==='1'?"样品分包":"样品自检" }}
            </el-tag>
          </template>
        </el-table-column> -->
        <el-table-column prop="sampTaskStatus" label="样品状态" width="120px" align="center">
          <template slot-scope="{row}">
            <el-tag v-if="row.smapStatus == 5" effect="dark" type="info">
              {{ SAMPLE_STATUS[row.smapStatus] }}
            </el-tag>
            <el-tag v-else effect="dark" :type="row.smapStatus | statusQualityFilter">
              {{ SAMPLE_STATUS[row.smapStatus] }}
            </el-tag>
          </template>
        </el-table-column>
        <el-table-column prop="collectUser" label="采样人" width="160" align="center" />
        <el-table-column prop="storeTime" label="入库时间" width="160" align="center" />

        <el-table-column fixed="right" align="center" width="180" label="操作">
          <template slot-scope="scope">
            <el-button type="text" @click="handleDetail(scope.row)">查看</el-button>
            <el-button v-if="scope.row.smapStatus === '0' || scope.row.smapStatus === '5'" type="text" @click="handleDel(scope.row)">删除样品</el-button>
            <el-button v-if="scope.row.smapStatus === '0' || scope.row.smapStatus === '5'" type="text" @click="handleAllEdit(scope.row)">修改</el-button>
          </template>
        </el-table-column>
      </el-table>
    </div>
    <div style="float: right">
      <pagination
        v-show="total>0"
        :total="total"
        :page.sync="searchForm.pageNumber"
        :limit.sync="searchForm.pageSize"
        @pagination="handleSearch"
      />
    </div>

    <el-dialog :title="currentSample + '-详情'" :visible.sync="sampleVisible" width="85%" center top="5vh">
      <el-form :model="sampleDetailForm" label-width="180px" label-position="right">
        <el-card style="margin-top: 5px;padding-bottom: 20px;">
          <div slot="header" class="clearfix">
            <div style="width: 3px;margin:auto 3px; height: 20px;background-color:steelblue;" />
            <span>基础信息</span>
          </div>
          <el-col :span="16" style="height:32px;">
            <el-form-item label-width="100" label="检测因子:">
              <span class="showTile">{{ sampleDetailForm.factorName }}</span>
            </el-form-item>
          </el-col>
          <el-col :span="8" style="height:32px;">
            <el-form-item label-width="100" label="检测位置:">
              <span class="showTile">{{ sampleDetailForm.factorPoint }}</span>
            </el-form-item>
          </el-col>
          <!--动态二级类别信息-->
        </el-card>
        <el-card v-for="item in sampleSecInfo" :key="item.groupKey" style="margin-top: 5px;padding-bottom: 20px;">
          <div v-if="item.groupName && item.groupName != ''" slot="header" class="clearfix">
            <div style="width: 3px;margin:auto 3px; height: 20px;background-color:steelblue;" />
            <span>{{ item.groupName }}</span>
          </div>
          <el-col v-for="(sitem,index) in item.params" :key="index" :span="8" style="height:32px;">
            <el-form-item label-width="100">
              <span slot="label">{{ sitem.name }}:</span>
              <span class="showTile">{{ sitem.value?sitem.value.toString():'' }}</span>
            </el-form-item>
          </el-col>
        </el-card>

        <el-card v-if="sampleDataInfo && sampleDataInfo.length > 0" style="margin-top: 5px">
          <div slot="header" class="clearfix">
            <div style="width: 3px;margin:auto 3px; height: 20px;background-color:steelblue;" />
            <span>现场检测因子信息</span>
          </div>
          <el-table border :data="sampleDataInfo" stripe>
            <el-table-column prop="factorName" label="检测因子项目" />
            <el-table-column label="因子结果集">
              <template slot-scope="{row}">
                <template v-if="row.measuredForm">
                  {{ '第一值: ' +row.measuredForm.firstVal + ' 第二值: ' + row.measuredForm.secondVal + " 均值: " + row.measuredForm.avgVal }}
                </template>
                <template v-else>
                  {{ row.factorData?row.factorData:'' }}
                </template>
              </template>
            </el-table-column>
            <el-table-column prop="checkEquipment" label="检测仪器">
              <template slot-scope="{row}">
                {{ row.checkEquipment&&row.checkEquipment.length>0?row.checkEquipment.replaceAll('^_^',' '):'' }}
              </template>
            </el-table-column>
            <el-table-column prop="theoreticalVal" label="理论值" />
            <el-table-column prop="groundConditions" label="测定值" />
          </el-table>
        </el-card>

        <el-card style="margin-top: 5px">
          <div slot="header" class="clearfix">
            <div style="width: 3px;margin:auto 3px; height: 20px;background-color:steelblue;" />
            <span>现场信息</span>
          </div>
          <el-col :span="12">
            <el-form-item label-width="100" label="采样地址:">
              <span class="showTile">{{ sampleDetailForm.sampleDataVo.collectLocation }}</span>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label-width="100" label="采样日期:">
              <span class="showTile">{{ sampleDetailForm.sampleDataVo.collectDate }}</span>
            </el-form-item>
          </el-col>
          <el-col :span="24">
            <el-form-item label-width="100" label="现场图片:">
              <div v-if="sampleImageList && sampleImageList.length > 0" class="demo-image__lazy">
                <el-image v-for="(url, index) in sampleImageList" :key="index" :src="url" :preview-src-list="sampleImageList" style="width: 100px; height: 100px;margin-left: 10px;" />
              </div>
            </el-form-item>
          </el-col>
        </el-card>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button @click="sampleVisible=false">关 闭</el-button>
      </div>
    </el-dialog>
    <el-dialog title="新增检测因子" :visible.sync="isEditFactors" width="65%" center top="5vh">

      <addFactor v-if="isEditFactors" ref="addFactor" :secd-class-id-edit.sync="chooseEditSecdClass" />

      <div slot="footer" class="dialog-footer" style="text-align: right;">

        <el-button @click="isEditFactors = false">取消</el-button>
        <el-button type="primary" @click="getAddFactorData">确认</el-button>
      </div>
    </el-dialog>
    <!--
    <addGroup ref="addGroup" @transmitData="transmitData" @handleCancel="getTabStatus" @handleConfim="getTabResultForSame" /> -->

    <el-dialog title="新增同系因子套餐" :visible.sync="isEditGroup" width="65%" center top="5vh">

      <addGroup v-if="isEditGroup" ref="addGroups" :secd-class-id-edit="chooseEditSecdClass" />

      <div slot="footer" class="dialog-footer" style="text-align: right;">
        <el-button @click="isEditGroup = false">取消</el-button>
        <el-button type="primary" @click="getAddGroupData">确认</el-button>
      </div>
    </el-dialog>

    <el-dialog :title="addTitle" :visible.sync="adddVisible" width="85%">
      <el-table
        ref="filterTable"
        :data="gridData"
        row-key="jobPlanFactorId"
        border
        :tree-props="{children: 'subFactors', hasChildren: 'hasChildren'}"
        @selection-change="dialogFactorChange"
      >
        <el-table-column align="center" :selectable="checkGridDataSelect" type="selection" width="55" />
        <el-table-column
          v-if="addTitle =='新增运输空白样'"
          property="className"
          label="检测类别"
          :filters="filtersClassNameArr"
          :filter-method="filterHandler"
        />
        <el-table-column
          v-else
          property="className"
          label="检测类别"
        />
        <el-table-column property="factorName" label="检测因子" align="center">
          <template slot-scope="{row}">
            <template v-if="row.isFactor == 1">
              <div v-if="row.factorName">{{ row.factorName }}</div>
              <el-tag v-else> 套 餐</el-tag>
            </template>
            <template v-else>
              {{ row.factorName }}
            </template>
          </template>
        </el-table-column>
        <el-table-column property="standardNo" label="标准号" align="center" />
        <el-table-column property="standardName" label="标准名称" align="center" />
        <el-table-column property="analysisMethod" label="分析方法" align="center" />
        <el-table-column property="factorPoint" label="采样点位" align="center" />
      </el-table>
      <div slot="footer" class="dialog-footer">
        <el-button @click="adddVisible = false">取 消</el-button>
        <el-button type="primary" @click="adddVisibleComit">确 认</el-button>
      </div>
    </el-dialog>

    <el-dialog :title="editSample + '-详情'" :visible.sync="editSampleVisible" width="85%" center top="5vh">
      <el-card style="margin-top: 5px;padding-bottom: 20px;">
        <div slot="header" class="" style="display:flex;justify-content: space-between;">
          <div style="display:flex;align-items: center;">
            <div style="width: 3px;margin:auto 3px; height: 20px;background-color:steelblue;" />
            <span>共有的检测因子信息</span>
          </div>
          <div>
            <el-button type="primary" plain @click="channgeAddress()">检测位置修改</el-button>
            <el-button type="primary" plain @click="editadd('factor')">新增因子</el-button>
            <el-button type="primary" plain @click="editadd('group')">新增同系因子套餐</el-button>
          </div>
        </div>
        <el-table
          :data="editSampleArr"
          border
          style="width: 100%"
        >
          <el-table-column type="index" width="50" label="序号" align="center" />
          <el-table-column prop="factorName" label="检测因子/套餐" />
          <el-table-column prop="analysisMethod" label="检测方法" />
          <el-table-column prop="standardNo" label="标准号" />
          <el-table-column prop="standardName" label="标准名称" />
          <el-table-column fixed="right" align="center" width="180" label="操作">
            <template slot-scope="scope">
              <el-button type="text" @click="editDel(scope.row,scope.$index)">删除</el-button>
            </template>
          </el-table-column>

        </el-table>
      </el-card>
      <div slot="footer" class="dialog-footer">
        <el-button @click="editSampleVisible=false">关 闭</el-button>
        <el-button type="primary" @click="editAllCommit">确 定</el-button>
      </div>
    </el-dialog>

    <el-dialog title="现场采样记录单下载" :visible.sync="downVisible" width="400px" center>
      <div style="width: 500px;margin:0 auto">
        <el-form :model="recordForm" label-width="90px">
          <el-form-item label="检测对象:">
            <el-select v-model="recordForm.classId" clearable style="width:240px" filterable placeholder="检测对象" @change="findSecClass">
              <el-option
                v-for="item in classArray"
                :key="item.id"
                :label="item.name"
                :value="item.id"
              />
            </el-select>
          </el-form-item>
          <el-form-item label="检测类别:">
            <el-select v-model="recordForm.secClassId" clearable style="width:240px" filterable placeholder="检测类别">
              <el-option
                v-for="item in secClassArray"
                :key="item.id"
                :label="item.name"
                :value="item.id"
              />
            </el-select>
          </el-form-item>
        </el-form>

      </div>
      <div slot="footer" class="dialog-footer">
        <el-row>
          <el-col :span="8" style="text-align: left;">
            <el-button type="primary" size="small" @click="allDownload">全部下载</el-button>
          </el-col>
          <el-col :span="16" style="text-align: right;">
            <el-button size="small" @click="downVisible=false">取消</el-button>
            <el-button type="primary" size="small" @click="confirmDownload">确认</el-button>
          </el-col>
        </el-row>
      </div>
    </el-dialog>
    <div v-if="factorGroupVisible">
      <el-dialog :title="title" :visible.sync="factorGroupVisible" append-to-body :close-on-click-modal="false" width="85%">
        <el-tabs v-model="activeName" @tab-click="tabClick">
          <el-tab-pane label="检测因子" name="1">
            <div>
              <el-row :gutter="10">
                <el-col :span="6">
                  <el-card class="card-left" shadow="never">
                    <div>
                      <el-tree
                        ref="tree"
                        class="filter-tree"
                        :data="factorTreeData"
                        :props="defaultProps"
                        highlight-current
                        default-expand-all
                        :expand-on-click-node="true"
                        style="height: 100%;"
                        @node-click="handleTreeFactorSearch"
                      />
                    </div>
                  </el-card>
                </el-col>
                <el-col :span="18">
                  <el-container>
                    <el-header height="45px">
                      <el-input v-model.trim="factorForm.fuzzy" style="width:320px" placeholder="请输入因子/标准号/检测标准/分析方法" @keyup.enter.native="handleFactorSearch" />
                      <el-button type="primary" style="margin-left: 10px" @click="handleFactorSearch">查询</el-button>
                    </el-header>
                    <el-main class="main-body">
                      <el-table
                        ref="multipleTable"
                        :data="showChoseData"
                        stripe
                        border
                        max-height="450px"
                        :header-cell-style="{background:'#ECF3FC'}"
                        @select="handleSelectChange"
                        @selection-change="handleSelectionChange"
                      >
                        <el-table-column type="selection" width="50" align="center" />
                        <el-table-column prop="className" label="检测对象" width="100px" align="center" />
                        <el-table-column prop="factorName" label="检测因子" align="center" />
                        <el-table-column prop="standardNo" label="标准号" align="center" />
                        <el-table-column prop="standardName" label="标准名称" min-width="130px" align="center" />
                        <el-table-column prop="cmaFlg" label="CMA" width="60" align="center">
                          <template slot-scope="{row}">
                            <el-tag :type="row.cmaFlg==='1'?'success':'danger'">{{ row.cmaFlg==='1'?'Y':'N' }}</el-tag>
                          </template>
                        </el-table-column>
                        <el-table-column prop="cnasFlg" label="CNAS" width="60" align="center">
                          <template slot-scope="{row}">
                            <el-tag :type="row.cnasFlg==='1'?'success':'danger'">{{ row.cnasFlg==='1'?'Y':'N' }}</el-tag>
                          </template>
                        </el-table-column>
                        <el-table-column prop="analysisMethod" label="分析方法" align="center" />
                      <!--                  <el-table-column prop="MoneyFormat" label="价格" align="center">-->
                      <!--                    <template slot-scope="{row}">-->
                      <!--                      {{ row.price|MoneyFormat }} 元-->
                      <!--                    </template>-->
                      <!--                  </el-table-column>-->
                      </el-table>
                    </el-main>
                    <el-footer height="45px">
                      <pagination
                        v-show="factTotal>0"
                        :total="factTotal"
                        :page.sync="factorForm.pageNumber"
                        :limit.sync="factorForm.pageSize"
                        @pagination="handleFactorSearch"
                      />
                    </el-footer>
                  </el-container>

                </el-col>
              </el-row>

            </div>

          </el-tab-pane>
          <el-tab-pane label="同系因子套餐" name="2">
            <same-meal ref="sameMeal" :clear-type="cleanAttr" :tree-node-id="treeNodeId" @transmitData="transmitData" @handleCancel="getTabStatus" @handleConfim="getTabResultForSame" />
          </el-tab-pane>
          <div>
            <el-divider content-position="left">已选检测因子</el-divider>
            <el-row style="min-height:36px;line-height: 30px">
              <el-col :span="4">
                <span>已选中检测因子:</span>
              </el-col>
              <el-col :span="20">
                <template v-if="choseFatcors && choseFatcors.length > 0">
                  <el-tag
                    v-for="item in choseFatcors"
                    :key="item.id"
                    closable
                    :disable-transitions="false"
                    style="margin:2px 3px"
                    @close="handleClose(item)"
                  >
                    {{ item.factorName }}
                  </el-tag>
                </template>
                <template v-else>
                  无
                </template>
              </el-col>
            </el-row>
          </div>
          <div>
            <el-divider content-position="left">已选套餐因子</el-divider>
            <el-row style="min-height:36px;line-height: 30px">
              <el-col :span="4">
                <span>已选中套餐因子:</span>
              </el-col>
              <el-col :span="20">

                <template v-if="choseGroupFatcors && choseGroupFatcors.length > 0">
                  <el-tag
                    v-for="item in choseGroupFatcors"
                    :key="item.id"
                    closable
                    type="success"
                    :disable-transitions="false"
                    style="margin:2px 3px"
                    @close="handleGroupClose(item)"
                  >
                    {{ item.factorName }}
                  </el-tag>
                </template>
                <template v-else>
                  无
                </template>
              </el-col>
            </el-row>

          </div>
        </el-tabs>
        <el-form v-if="!isEdit">

          <el-divider content-position="left">分包判定</el-divider>
          <el-row :gutter="10">
            <el-col :span="8">
              <el-form-item label="是否分包:" label-width="100px">
                <el-select v-model="fbType" placeholder="请选择是否分包" @change="changeFbType">
                  <el-option value="0" label="否" />
                  <el-option value="1" label="是" />
                </el-select>
              </el-form-item>
            </el-col>
            <el-col :span="8">
              <el-form-item v-if="fbType == 1" label="分包机构" label-width="110px">

                <el-select v-model="FbValid" clearable placeholder="请选择分包机构">
                  <el-option
                    v-for="item in FbValidArr"
                    :key="item.id"
                    :label="item.judgeOrganName"
                    :value="item.id"
                  />
                </el-select>

              </el-form-item>
            </el-col>
          </el-row>
          <el-divider content-position="left">因子配置</el-divider>
          <el-row :gutter="10">
            <el-col :span="8">
              <el-form-item v-if="currentNodeId === '002001'" label="均值类型:" label-width="100px">
                <el-select v-model="meanType" placeholder="请选择均值类型">
                  <el-option value="0" label="日均值" />
                  <el-option value="1" label="时均值" />
                  <el-option value="2" label="八小时均值" />
                </el-select>
              </el-form-item>
            </el-col>
            <el-col :span="8">
              <el-form-item label="天数:" label-width="100px">
                <el-input-number v-model="setDay" controls-position="right" :min="1" :step="1" :precision="0" />
              </el-form-item>
            </el-col>
            <el-col :span="8">
              <el-form-item label="频次(次/天):" label-width="110px">
                <el-input-number v-model="frequency" :disabled="flag" controls-position="right" :max="maxTotal" :min="1" :step="1" :precision="0" />
              </el-form-item>
            </el-col>
            <el-col :span="24">
              <el-form-item :label="addressArray && addressArray.length >0 ?'检测位置1:':'检测位置:'" label-width="100px">
                <el-input v-model="lookPosition" placeholder="检测位置" style="width: 250px;margin-right:3px" />
              </el-form-item>
            </el-col>
          </el-row>
          <el-row>
            <el-col v-for="(item, index) in addressArray" :key="item.key" :span="24">
              <el-form-item :label="'检测位置'+(index+2)+':'" label-width="100px">
                <el-input v-model="item.value" placeholder="检测位置" style="width: 250px;margin-right:3px" />
                <el-button v-if="currentNodeId !== '002001' && currentNodeId !== '002003'" type="text" size="small" @click.prevent="removeAddDomain(item)">删除</el-button>
              </el-form-item>
            </el-col>
            <el-col v-if="currentNodeId !== '002003' && currentNodeId !== '002001'" :span="24" style="padding-left:20px">
              <el-form-item>
                <el-button type="primary" @click="addAddress">添加位置</el-button>
              </el-form-item>
            </el-col>
          </el-row>
        </el-form>
        <div slot="footer" class="dialog-footer">
          <el-button @click="clearAddDlog">取消</el-button>
          <el-button type="primary" @click="confirmChoseFactor">确认</el-button>
        </div>
      </el-dialog>
    </div>
  </div>
</template>

<script>
import * as sampleServer from '@/api/sample'
import * as stockServer from '@/api/stock'
import * as factorServer from '@/api/factor'
import * as dictServer from '@/api/dict'
import * as formConfigurationsServer from '@/api/system/formConfigurations'

import { uuid } from 'vue-uuid'
import sameMeal from './components/sameMeal.vue'

import addFactor from './components/addFactor.vue'
import addGroup from './components/addGroup.vue'
import Pagination from '@/components/Pagination' // Secondary package based on el-pagination
const SAMPLE_STATUS = {
  '0': '待采样',
  '1': '已采样',
  '10': '待复核',
  '2': '待组长确认',
  '3': '负责人待审核',
  '4': '审核通过',
  '5': '审核不通过',
  '6': '已入库',
  '8': '已出库',
  '9': '入库中'
}
const MEAN_STATUS = {
  '0': '日均值',
  '1': '时均值',
  '2': '八小时均值'
}
export default {
  components: { Pagination, sameMeal, addFactor, addGroup },
  filters: {
    statusQualityFilter(status) {
      if (status === '0' || status === '5') {
        return ''
      } else if (status === '9') {
        return 'danger'
      } else if (status < 4) {
        return 'warning'
      } else if (status < 9) {
        return 'success'
      } else {
        return 'danger'
      }
    }
  },
  data() {
    return {
      isEdit: false,
      isEditFactors: false,
      isEditGroup: false,
      chooseEditSecdClass: '',

      editSample: '',
      editSampleArrs: [],
      editSampleVisible: false,
      editSampleArr: [],
      filtersClassNameArr: [],
      adddVisible: false,
      addTitle: '新增平行样',
      gridData: [],
      addObj: {
        sampleId: '',
        sampleTaskId: '',
        type: '',
        number: '',
        jobPlanFactorIds: '',
        groups: []
      },

      title: '新增样品',
      treeNodeInfo: '',
      choseGroupFatcors: [], // 套餐因子
      authType: '',
      fbType: '0',
      FbValid: '',
      FbValidArr: [],
      factorGroupVisible: false,
      activeName: '1',
      cleanAttr: '',
      factorTreeData: [],
      factorTreeDatas: [],
      defaultProps: {
        children: 'children',
        label: 'name',
        id: 'id'
      },
      factTotal: 0,
      factorForm: {
        fuzzy: '',
        classId: '',
        factorName: '',
        pageNumber: 1,
        pageSize: 10
      },
      showChoseData: [],
      addressArray: [],
      groupAddressArray: [],
      setDay: 1,
      frequency: 1, // 频次
      meanType: '0',
      currentNodeId: '',
      currentGroupNodeId: '',
      lookPosition: '',
      maxTotal: 10,
      factorMultipleSelection: [],
      choseFatcors: [],
      flag: false,
      currentUUid: '',

      SAMPLE_STATUS,
      MEAN_STATUS,
      sampleData: [],
      searchForm: {
        sampTaskId: '',
        sampleNo: '',
        sampStatus: '',
        pageNumber: 1,
        pageSize: 10
      },
      total: 0,

      currentSample: '',
      sampleDetailForm: {
        factorName: '',
        factorPoint: '',
        secdClassName: '',
        factorDataVos: [],
        sampleDataVo: {
          collectDate: '',
          collectLocation: '',
          imageList: [],
          sampleData: [],
          specialNote: ''
        },
        sampleJobVo: {
          projectName: '',
          jobRemark: ''
        }
      },
      sampleImage: '',
      sampleVisible: false,
      sampleImageList: [],
      downVisible: false,
      recordForm: {
        taskId: '',
        classId: '',
        secClassId: '',
        sampleDate: ''
      },
      editSampItemIdArr: [],
      classArray: [],
      secClassArray: [],
      sampleDetails: [],
      sampleDataInfo: [],
      sampleSecInfo: [],
      multipleSelection: [], // 选中数据数组
      treeNodeId: '', // tree检测因子选中后的id
      isEditAdd: false,
      editAllParamsPoint: '',
      editAllParams: {
        point: '',
        sampleIds: [],
        deleteMethodIds: [],
        deleteGroupIds: [],
        addMethodIds: [],
        groups: [{
          id: '',
          subCheckStandardIds: ''
        }]
      }
    }
  },
  created() {
    this.getClassList()
    if (this.$route.params.sampTaskId) {
      this.searchForm.sampTaskId = this.$route.params.sampTaskId
      this.handleSearch()
    }
  },
  methods: {
    // 修改样品编号
    updateSampleNo(a, b) {
      const params = {
        id: a,
        sampleNo: b
      }
      stockServer.updateSampleNo(params).then(res => {
        this.$message.success(res.message)
      })
    },
    filterHandler(value, row, column) {
      const property = column['property']
      return row[property] === value
    },
    dialogFactorChange(val) {
      this.factorMultipleSelection = val
    },
    handleCommand(v) {
      if (this.multipleSelection && this.multipleSelection.length > 0) {
        const params = {
          sampleId: this.multipleSelection[0].sampItemId,
          secdClassId: this.multipleSelection[0].secdClassId,
          type: 1,
          number: []
        }
        stockServer.getFactorsBySampleId(params).then(res => {
          const arr = []
          if (res.code === 200 && res.result) {
            res.result.map((item) => {
              arr.push({
                text: item.className,
                value: item.className
              })
              if (item.subFactors != null) {
                item.subFactors.map((item1) => {
                  this.$set(item1, 'groupsjobPlanFactorId', item.jobPlanFactorId)
                  this.$set(item1, 'groupInclude', 1)
                })
              }
            })
            this.gridData = res.result

            const map = new Map()
            for (const item of arr) {
              if (!map.has(item.text)) {
                map.set(item.text, item)
              }
            }

            this.filtersClassNameArr = [...map.values()]
          }
        })
        if (v == '新增密码样' && this.multipleSelection.length > 1) {
          this.$message.error('错误提示：新增密码样只可选择一个样品!')
          return
        } else if (v == '新增密码样' && this.multipleSelection.length == 1) {
          this.addTitle = '新增密码样'
        }

        if (v == '新增平行样' && this.multipleSelection.length > 1) {
          this.$message.error('错误提示：新增平行样只可选择一个样品!')
          return
        } else if (v == '新增平行样' && this.multipleSelection.length == 1) {
          this.addTitle = '新增平行样'
        }

        if (v == '新增运输空白样') {
          this.addTitle = '新增运输空白样'
        }
        if (v == '新增子样品') {
          this.addTitle = '新增子样品'
        }
        if (v == '新增全程序空白样') {
          this.addTitle = '新增全程序空白样'
        }
        // if (v == '新增全程序空白样') {

        // }

        this.adddVisible = true
        // const samples = this.multipleSelection.map(i => {
        //   return i.sampleNo
        // })
        // const url = '/api/word/downLoadHandover?secdClassId=' + this.multipleSelection[0].secdClassId + '&sampleNos=' + samples.toString()
        // window.open(url)
      } else {
        this.$message.warning('至少选择一条记录')
      }
    },

    checkGridDataSelect(row, rowIndex) {
      // 绑定参数表格禁用
      return row.isFactor == '0' // 当满足什么条件时启用
    },
    adddVisibleComit() {
      if (this.factorMultipleSelection.length == 0) {
        this.$message.warning('请选择检测因子')
        return
      }
      console.log(this.addTitle, 'this.addTitle')
      if (this.addTitle == '新增平行样') {
        this.addObj.type = 1
      } else if (this.addTitle == '新增全程序空白样') {
        this.addObj.type = 2
      } else if (this.addTitle == '新增运输空白样') {
        this.addObj.type = 3
      } else if (this.addTitle == '新增子样品') {
        this.addObj.type = 4
      } else if (this.addTitle == '新增密码样') {
        this.addObj.type = 5
      }
      this.addObj.sampleTaskId = this.$route.params.sampTaskId
      this.addObj.sampleId = this.multipleSelection[0].sampItemId
      this.addObj.number = this.multipleSelection.length
      this.addObj.sampleTaskId = this.$route.params.sampTaskId
      this.addObj.sampleId = this.multipleSelection[0].sampItemId
      this.addObj.number = this.multipleSelection.length
      const jobPlanFactorIds = []
      const jobPlanSubFactorIds = []
      const arr = []
      const groups = {}
      this.factorMultipleSelection.map((item) => {
        if (item.groupInclude == 1) {
          groups.jobPlanFactorId = item.groupsjobPlanFactorId
          jobPlanSubFactorIds.push(item.jobPlanFactorId)
        } else {
          jobPlanFactorIds.push(item.jobPlanFactorId)
        }
      })
      groups.jobPlanSubFactorIds = jobPlanSubFactorIds
      arr.push(groups)
      this.addObj.jobPlanFactorIds = jobPlanFactorIds
      this.addObj.groups = arr
      if (groups.jobPlanSubFactorIds.length == 0) {
        delete this.addObj.groups
      }
      stockServer.addQualityControl(this.addObj).then(res => {
        if (res.code == 200) {
          this.$message({
            type: 'success',
            message: res.message
          })
        }
      })
      this.handleSearch()
      this.adddVisible = false
    },

    selectAll() {
      this.$refs.mulTable.clearSelection()
    },
    // 编辑
    // 获取选中新增因子
    getAddFactorData() {
      const factorArr = this.$refs.addFactor.multipleSelection
      console.log(factorArr, 'factorArr')
      if (factorArr.length == 0) {
        this.$message.warning('请选择检测因子')
        return
      }
      const arr = [...this.editSampleArr, ...factorArr]
      const map = new Map()
      for (const item of arr) {
        if (!map.has(item.standardCode)) {
          map.set(item.standardCode, item)
        }
      }

      this.editSampleArr = [...map.values()]
      this.isEditFactors = false
    },

    // 获取选中套餐
    getAddGroupData(v) {
      const groupArr = this.$refs.addGroups.confirmGroupChoseFactor()

      this.editSampleArr = [...this.editSampleArr, ...groupArr]
      // this.$nextTick(() => {
      //   const groupArr = this.$refs.addGroups.retListArrays
      //   console.log(this.$refs.addGroups.retListArrays, 3333)
      //   this.editSampleArr = [...this.editSampleArr, ...groupArr]
      // })
      this.isEditGroup = false
    },
    // 列表复选框选中  需同地址同二级类
    checkboxSelect(row, rowIndex) {
      if (row.sampleType != 0) {
        return false
      } else {
        if (this.multipleSelection.length > 0) {
          if (row.secdClassId == this.multipleSelection[0].secdClassId && row.factorPoint == this.multipleSelection[0].factorPoint) {
            return true
          } else {
            return false
          }
        } else {
          return true
        }
      }
    },
    clearAddDlog() {
      this.activeName = '1'
      this.factorForm.fuzzy = ''
      this.factorGroupVisible = false
    },
    // tabClick切换事件
    tabClick(target, action) {
      console.log(target.name, action)
      if (target.name == 2 && this.treeNodeId) {
        this.$refs.sameMeal.getFactorGroup(this.treeNodeId)
      } else {
        if (this.choseGroupFatcors.length > 0) {
          console.log(this.factorTreeData, 'factorTreeData')
          const chooseTcId = this.choseGroupFatcors[0].secdClassId.slice(0, 3)
          const arr = []
          arr.push(this.factorTreeData.find((v) => {
            return v.id == chooseTcId
          }))
          this.factorTreeData = arr
        } else {
          this.getTreeClassList()
        }

        this.$forceUpdate()
      }
    },
    // 批量编辑提交
    editAllCommit() {
      // const arr = []
      // this.multipleSelection.map((item) => {
      //   arr.push(item.sampItemId)
      // })
      this.editAllParams.point = this.editAllParamsPoint || ''
      this.editAllParams.sampleIds = []
      this.editAllParams.deleteMethodIds = []
      this.editAllParams.deleteGroupIds = []
      this.editAllParams.addMethodIds = []
      this.editAllParams.groups = []

      this.editAllParams.sampleIds = this.editSampleArrs
      const allFactors = []
      const allGroucp = []

      const params = {
        sampItemIds: this.editSample
      }
      console.log(this.editSampleArr, 33333)
      this.editSampleArr.map((item) => {
        if (item.isFactor == 1) {
          allGroucp.push({
            id: item.groupId || item.checkStandardId,
            subCheckStandardIds: item.factorIds
          })
        } else {
          allFactors.push(item.standardCode)
        }
      })

      console.log(allFactors, allGroucp, 'allGroucp')
      sampleServer.factorListEdit(params).then(res => {
        if (res.code == 200) {
          const groups = []
          const oldFactors = []
          const oldGroucp = []
          res.result.map((item) => {
            if (item.isFactor == 0) {
              oldFactors.push(item.checkStandardId)
            } else {
              oldGroucp.push(item.checkStandardId)
            }
          })
          // // 因子
          console.log(oldFactors, oldGroucp, 'oldFactors')
          if (allFactors.length == 0) {
            if (oldFactors.length > 0) {
              this.editAllParams.deleteMethodIds = oldFactors
            } else {
              this.editAllParams.deleteMethodIds = []
            }
            this.editAllParams.addMethodIds = []
          } else if (allFactors.length > 0) {
            if (oldFactors.length > 0) {
              oldFactors.map((item) => {
                if (!allFactors.includes(item)) {
                  this.editAllParams.deleteM3ethodIds.push(item)
                }
              })
              allFactors.map((item) => {
                if (!oldFactors.includes(item)) {
                  this.editAllParams.addMethodIds.push(item)
                }
              })
            } else {
              this.editAllParams.deleteMethodIds = []
              this.editAllParams.addMethodIds = allFactors
            }
          }

          // 套餐

          if (allGroucp.length == 0) {
            if (oldGroucp.length > 0) {
              this.editAllParams.deleteGroupIds = oldGroucp
            } else {
              this.editAllParams.deleteGroupIds = []
            }
            this.editAllParams.groups = []
          } else if (allGroucp.length > 0) {
            if (oldGroucp.length == 0) {
              this.editAllParams.deleteGroupIds = []
              this.editAllParams.groups = allGroucp
            } else {
              oldGroucp.map((item) => {
                if (!allGroucp.includes(item.id)) {
                  this.editAllParams.deleteGroupIds.push(item)
                }
              })
              const groups = []
              allGroucp.map((item) => {
                if (!oldGroucp.includes(item.standardCode) || !oldGroucp.includes(item.standardCode)) {
                  groups.push({
                    'id': item.groupId,
                    'subCheckStandardIds': item.factorIds
                  })
                  console.log(groups, 'groups')
                }
              })
              this.editAllParams.groups = groups
            }
          }

          this.$nextTick(() => {
            sampleServer.updateBySampleIds(this.editAllParams).then(res => {
              console.log(res)
              if (res.code == 200) {
                this.$message({
                  type: 'success',
                  message: res.message
                })
                this.editSampleVisible = false
                this.handleSearch()
              }
            })
          })
        }
      })
    },
    // 传递套餐数据
    transmitData(v) {
      this.choseGroupFatcors = []
      this.choseGroupFatcors.push(v)
      console.log({ ...this.choseGroupFatcors }, '传递数据')
    },
    // 分包判定
    changeFbType(val, row) {
      console.log(val, row)
      if (val == 0) {
        this.FbValidArr = []
      } else {
        sampleServer.findValidList().then(res => {
          console.log(res)
          this.FbValidArr = res.result
          // if (res.code === 200) {
          //    this.FbValid
          // }
        })
      }
      // findValidList
    },
    getFreqList() {
      dictServer.findMonitorFreq().then(result => {
        if (result.code === 200) {
          this.checkFreqArray = result.result
        }
      })
    },
    getDicKey(type, code) {
      dictServer.getDicKey(code).then(result => {
        if (result.code === 200) {
          this[type] = result.result
        }
      })
    },
    getTreeClassList() {
      dictServer.findTreeClasses().then(res => {
        this.factorTreeData = res.result || []
      })
    },

    addGroup() {
      this.getFreqList()
      this.getTreeClassList()
      this.handleSearch()
      this.factorGroupVisible = true
    },
    handleSearch() {
      if (this.searchForm.sampTaskId) {
        sampleServer.findSampTaskDetailByCondition(this.searchForm).then(res => {
          if (res.code === 200) {
            this.sampleData = res.result.records
            this.factorForm.authType = res.result.authType
            this.total = res.result.total
          }
        })
      }
    },
    addFactor() {
      // 获取UUID
      this.currentUUid = uuid.v4().replaceAll('-', '')

      this.choseFatcors = []
      this.multipleSelection = []
      this.maxTotal = 10
      // this.handleFactorSearch()
      if (this.currentNodeId && this.currentNodeId.length > 0) {
        this.handleFactorSearch()
        if (this.currentNodeId === '002003') { // 厂界无组织/ 环境空气 自动生成5个点位
          this.$nextTick(() => {
            for (var i = 0; i < 4; i++) {
              this.addressArray.push({
                value: '',
                windNum: 3,
                key: Date.now() + i
              })
            }
          })
        } else if (this.currentNodeId === '002001') {
          this.$nextTick(() => {
            for (var i = 0; i < 3; i++) {
              this.addressArray.push({
                value: '',
                windNum: 3,
                key: Date.now() + i
              })
            }
          })
        }
      }
      // 清空设定值
      this.setDay = 1
      this.frequency = 1
      this.addressArray = []
      this.lookPosition = ''
      this.meanType = ''
      this.factorVisible = true
    },
    choseGroup() {
      this.currentUUid = uuid.v4().replaceAll('-', '')
      this.cleanAttr = this.currentUUid // 清空弹窗信息的动态触发判定
      this.startFactorGroup = ''
      this.groupAddressArray = []
      this.multiplGroupeSelection = []
      this.choseGroupFatcors = []
      this.factorGroupVisible = true
    },

    confirmChoseFactor() {
      if (!this.choseFatcors || this.choseFatcors.length <= 0 && (!this.choseGroupFatcors || this.choseGroupFatcors.length <= 0)) {
        this.$message.warning('因子不能为空')
        return
      }
      if (this.fbType == 1 && !this.FbValid) {
        this.$message.warning('请选择分包机构')
        return
      }
      if (!this.lookPosition || this.lookPosition.length <= 0) {
        this.$message.warning('初始检测位置不能为空')
        return
      }

      const params = {
        'secdClassId': '001002',
        'secdClassName': '地表水',
        'sampTaskId': 279,
        'fbFlag': this.fbType,
        'frequency': 1,
        'dayCount': 1,
        'factorPoint': '1#',
        'factorGroupKey': 'ereagerg-erthehq=-reqh',
        'factorTdos': []
      }
      // 分包机构ID和名字
      this.FbValidArr.map((item) => {
        if (item.id == this.FbValid) {
          params.organId = item.id
          params.organName = item.judgeOrganName
        }
      })
      // 天数
      params.dayCount = this.setDay
      // 频次
      params.frequency = this.frequency
      // 添加二级ID和二级名称
      if (this.choseGroupFatcors.length > 0) {
        params.secdClassId = this.choseGroupFatcors[0].secdClassId
        params.secdClassName = this.choseGroupFatcors[0].secdClassName
      } else {
        params.secdClassId = this.treeNodeInfo.id
        params.secdClassName = this.treeNodeInfo.name
      }
      // 任务ID
      params.sampTaskId = this.$route.params.sampTaskId
      // 位置
      const addressJson = []
      addressJson.push(this.lookPosition)
      if (this.addressArray.length > 0) {
        this.addressArray.map((item) => {
          if (item.value) {
            addressJson.push(item.value)
          }
        })
      }
      params.factorPoint = addressJson.toString()
      if (this.choseFatcors.length > 0) {
        this.choseFatcors.map((item) => {
          this.$set(item, 'isFactor', 0)
          this.$set(item, 'dataEntryStep', 1)
        })
      }
      if (this.choseGroupFatcors.length > 0) {
        this.choseGroupFatcors.map((item) => {
          this.$set(item, 'isFactor', 1)
          this.$set(item, 'dataEntryStep', 1)
        })
      }

      // 因子动态参数
      const dynamic = {}
      if (this.currentNodeId === '002001') {
        dynamic.meanType = this.meanType
        dynamic.meanName = this.MEAN_STATUS[this.meanType]
        this.$nextTick(() => {
          params.dynamicParam = JSON.stringify(dynamic)
          //   console.log({ ...params }, 'paramsy')
        })
      }
      // 因子
      if (this.choseFatcors.length > 0) {
        this.choseFatcors.map((item) => {
          this.$set(item, 'checkStandardId', item.standardCode)
          params.factorTdos.push(item)
        })
      }
      // 套餐
      if (this.choseGroupFatcors.length > 0) {
        params.factorTdos.push(this.choseGroupFatcors[0])
      }
      this.$nextTick(() => {
        sampleServer.addSample(params).then(res => {
          if (res.code == 200) {
            this.$message({
              type: 'success',
              message: res.message
            })
          }

          this.factorGroupVisible = false
        })
      })
    },
    handleSelectChange(val, row) {
      // 先判定是否取消
      if (val) {
        if (val.indexOf(row) === -1) {
          const index = this.choseFatcors.findIndex(i => i.id === row.id)
          this.choseFatcors.splice(index, 1)
        }
      }
    },
    handleClose(item) {
      // 移除存储的因子
      this.choseFatcors.splice(this.choseFatcors.indexOf(item), 1)
      this.$refs.multipleTable.toggleRowSelection(item, false)
    },
    handleGroupClose(item) {
      // 移除存储的因子
      this.choseGroupFatcors.splice(this.choseGroupFatcors.indexOf(item), 1)
      this.$refs.groupMultipleTable.toggleRowSelection(item, false)
    },
    handleTreeFactorSearch(val, node) {
      this.treeNodeInfo = val
      this.treeNodeId = val.id
      // debugger
      // console.log(val,node);
      if (val.id.startsWith('004')) {
        this.flag = true
      } else {
        this.flag = false
      }
      if (!val.children || val.children == null) {
        // if (!this.currentNodeId || this.currentNodeId !== val.id) {
        this.addressArray = []
        this.currentNodeId = val.id
        this.currentNodeName = val.name
        this.factorForm.classId = node.parent.data.id
        this.factorForm.secdClassId = val.id
        this.factorForm.factorName = ''
        this.factorForm.pageNumber = 1
        this.handleFactorSearch()
        // 清空已经选择的信息
        this.choseFatcors = []
        this.multipleSelection = []

        if (val.id === '002001' && this.meanType === '0') {
          this.maxTotal = 1
        } else if (val.id === '004001') {
          this.maxTotal = 2
        } else {
          this.maxTotal = 10
        }
        if (val.id === '002003') { // 厂界无组织/ 环境空气 自动生成5个点位
          this.$nextTick(() => {
            for (var i = 0; i < 4; i++) {
              this.addressArray.push({
                value: '',
                windNum: 3,
                key: Date.now() + i
              })
            }
          })
        } else if (val.id === '002001') {
          this.$nextTick(() => {
            for (var i = 0; i < 3; i++) {
              this.addressArray.push({
                value: '',
                windNum: 3,
                key: Date.now() + i
              })
            }
          })
        }
        // }
        // 为底层的时候
      }
    },
    handleFactorSearch() {
      if (this.currentNodeId && this.currentNodeId.length > 0) {
        factorServer.getFactorListForPage(this.factorForm).then(res => {
          if (res.code === 200) {
            this.showChoseData = res.result.records || []
            this.showChoseData.map((item) => {
              this.$set(item, 'secdClassId', this.treeNodeInfo.id)
              this.$set(item, 'secdClassName', this.treeNodeInfo.name)
            })
            this.factTotal = res.result.total
          }
        })
      }
    },
    addAddress() {
      this.$nextTick(() => {
        this.addressArray.push({
          value: '',
          windNum: 3,
          key: Date.now()
        })
      })
    },

    // 单个删除样品
    handleDel(row) {
      this.$prompt('请输入删除原因', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消'
      }).then(({ value }) => {
        const params = {
          id: row.sampItemId,
          message: value
        }
        sampleServer.delSampTaskDetailByCondition(params).then(res => {
          if (res.code === 200) {
            this.$message({
              type: 'success',
              message: '删除成功!'
            })
            this.handleSearch()
          }
        })
      })
    },
    editadd(row) {
      // this.factorGroupVisible = true
      if (row == 'factor') {
        this.isEditFactors = true
        this.isEditGroup = false
        // this.$refs.addFactor.secdClassIdEdit = this.chooseEditSecdClass
        // console.log(this.$refs.addFactor.secdClassIdEdit)
      } else {
        this.isEditGroup = true
        this.isEditFactors = false
        console.log(this.isEditGroup, 123)
      }
      // this.getFreqList()
      // this.getTreeClassList()
      // this.handleSearch()
      // this.title = ''
      // this.isEdit = true
    },
    // 检测位置修改
    channgeAddress() {
      this.$prompt('请输入检测位置', '修改', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        inputValue: this.editAllParamsPoint,
        inputErrorMessage: '输入不能为空',
        inputValidator: (value) => {
          if (!value) {
            return '输入不能为空'
          }
        }

      }).then(({ value }) => {
        this.editAllParamsPoint = value
      })
    },
    // 编辑删除
    editDel(item, index) {
      this.editSampleArr.splice(index, 1)
    },
    handleClearTabs(done) {
      // 数据清空处理
      this.$confirm('确认关闭？').then(_ => {
        done()
      }).catch(_ => {})
    },
    getTabStatus(val) {
      // 数据清空处理
      if (!val) {
        this.factorGroupVisible = false
      }
    },
    getTabResultForSame(val) { // 同系套餐数据获取
      this.$nextTick(() => {
        if (this.planForm.factorTdoList && this.planForm.factorTdoList.length > 0) {
          this.planForm.factorTdoList = this.planForm.factorTdoList.concat(val)
        } else {
          this.planForm.factorTdoList = val
        }
      })
      this.factorGroupVisible = false
    },
    handleSelectionChange(val) {
      this.multipleSelection = val
      if (val) {
        val.forEach(i => {
          const ob = this.choseFatcors.find(j => j.id === i.id)
          if (!ob) {
            this.choseFatcors.push(i)
          }
        })
      }
    },
    // 复选框事件
    handleSelectionChanges(val) {
      this.multipleSelection = val
      console.log(this.multipleSelection)
      this.$nextTick(() => {
        this.checkboxSelect()
      })
    },
    // 批量修改
    handleAllEdit(row) {
      console.log(row)
      const arr = []
      if (row.sampItemId) {
        arr.push(row.sampItemId)
        this.editSampItemIdArr = arr
        this.editAllParamsPoint = row.factorPoint
        this.chooseEditSecdClass = row.secdClassId
      } else {
        if (this.multipleSelection.length == 0) {
          this.$message({
            message: '请选择需要修改的数据',
            type: 'warning'
          })
          return
        } else {
          this.multipleSelection.map((item) => {
            arr.push(item.sampItemId)
          })
          this.editAllParamsPoint = this.multipleSelection[0].factorPoint
          this.chooseEditSecdClass = this.multipleSelection[0].secdClassId
        }
      }

      const params = {
        sampItemIds: arr.toString()
      }
      this.editSample = arr.toString()
      this.editSampleArrs = arr
      console.log(this.editSample, arr)
      this.editSampleVisible = true

      sampleServer.factorListEdit(params).then(res => {
        if (res.code == 200) {
          this.editSampleArr = res.result
          this.editSampleArr.map((item) => {
            item.standardCode = item.checkStandardId
          })
        }
      })
    },
    handleDetail(row) {
      // 获取数据
      this.currentSample = row.sampleNo
      this.sampleImageList = []
      this.sampleDataInfo = [] // 因子信息
      this.sampleSecInfo = [] // 二级类别信息
      this.sampleImage = ''
      var baseUrl = this.$store.getters.sysBaseUrl + '/cyImg/'
      stockServer.getSampleDataBySampItemId(row.sampItemId).then(res => {
        if (res.code === 200 && res.result) {
          this.sampleDetailForm = res.result || {}
          this.$nextTick(() => {
            // 提取图片
            this.sampleImageList = res.result.sampleDataVo.imageList.map(i => {
              return baseUrl + i
            })
            // 二级类别
            this.sampleSecInfo = res.result.sampleDataVo.sampleData || []
            var nfactorDataVos = res.result.factorDataVos.filter(i => (i.dataEntryStep === '1' && i.checkStandardId.indexOf('100004-') === -1)) || []
            // 因子
            this.sampleDataInfo = nfactorDataVos.map(i => {
              if (i.measuredFormVal && i.measuredFormVal.length > 0) {
                this.$set(i, 'measuredForm', JSON.parse(i.measuredFormVal))
              }
              return i
            })
          })
          this.sampleVisible = true
        }
      })
      // 封装展示数据
    },
    getClassList() {
      dictServer.findFstClasses().then(res => {
        this.classArray = res.result || []
      })
    },
    findSecClass(val) {
      this.recordForm.secClassId = ''
      dictServer.findSecdClassByClassId(val).then(res => {
        this.secClassArray = res.result || []
      })
    },
    handleAddRecords() {
      this.recordForm.taskId = this.$route.params.sampTaskId
      this.recordForm.classId = ''
      this.recordForm.secClassId = ''
      this.recordForm.sampleDate = ''
      this.downVisible = true
    },
    allDownload() {
      const url = '/api/word/downBlankSampleRecordByTaskId?taskId=' + this.recordForm.taskId
      window.open(url)
    },
    downloadTask() {
      const url = '/api/word/downMission?sampTaskId=' + this.searchForm.sampTaskId
      window.open(url)
    },
    confirmDownload() {
      // console.log(this.recordForm, 333)
      const params = {
        secdClassId: this.recordForm.secClassId,
        fileCode: 'XC'
      }

      const data = {
        sampTaskId: 419,
        secdClassId: this.recordForm.secClassId
      }
      // 获取到默认模板
      let htmlData = ''
      formConfigurationsServer.findByTemplateData(params).then(res => {
        htmlData = res.result.tableData

        // htmlData = res.result.tableData
        // const josns = '"<table style=\"border-collapse: collapse; width: 100%; margin-left: auto; margin-right: auto;\" border=\"1\"><colgroup><col style=\"width: 9.96678%;\"><col style=\"width: 9.96678%;\"><col style=\"width: 9.96678%;\"><col style=\"width: 9.96678%;\"><col style=\"width: 9.96678%;\"><col style=\"width: 9.96678%;\"><col style=\"width: 9.96678%;\"><col style=\"width: 0.830565%;\"><col style=\"width: 8.56364%;\"><col style=\"width: 20.5892%;\"></colgroup>\n<tbody>\n<tr>\n<td style=\"border-style: hidden; text-align: center;\" colspan=\"5\"><strong>泰科检测科技江苏有限公司</strong></td>\n<td style=\"border-style: hidden; text-align: center;\" colspan=\"3\">&nbsp;</td>\n<td style=\"border-style: hidden; text-align: center;\"><strong>控制编号：</strong></td>\n<td style=\"border-style: hidden; text-align: center;\">&nbsp;</td>\n</tr>\n</tbody>\n</table>\n<hr>\n<p style=\"text-align: center;\"><span style=\"font-size: 18pt;\"><strong>道路交通噪声检测现场记录表</strong></span></p>\n<table style=\"border-collapse: collapse; width: 100%; height: 291.047px; margin-left: auto; margin-right: auto;\" border=\"1\"><colgroup><col style=\"width: 12.5307%;\"><col style=\"width: 12.5307%;\"><col style=\"width: 14.9877%;\"><col style=\"width: 7.04341%;\"><col style=\"width: 7.04341%;\"><col style=\"width: 3.9312%;\"><col style=\"width: 4.095%;\"><col style=\"width: 3.6036%;\"><col style=\"width: 3.5217%;\"><col style=\"width: 5.15971%;\"><col style=\"width: 6.79771%;\"><col style=\"width: 6.71581%;\"><col style=\"width: 5.97871%;\"><col style=\"width: 6.06061%;\"></colgroup>\n<tbody>\n<tr style=\"height: 22.3906px;\">\n<td style=\"height: 22.3906px; text-align: center;\"><strong>委托公司</strong></td>\n<td style=\"height: 22.3906px; text-align: center;\">1cyyqxh</td>\n<td style=\"height: 22.3906px; text-align: center;\"><strong>检测日期</strong></td>\n<td style=\"height: 22.3906px; text-align: center;\" colspan=\"2\">cyyqbh</td>\n<td style=\"height: 22.3906px; text-align: center;\" colspan=\"5\"><strong>天气情况</strong></td>\n<td style=\"height: 22.3906px; text-align: center;\"><strong>昼间</strong></td>\n<td style=\"height: 22.3906px; text-align: center;\"><strong>夜间</strong></td>\n<td style=\"height: 22.3906px; text-align: center;\" colspan=\"2\"><strong>声级校准</strong></td>\n</tr>\n<tr style=\"height: 44.75px; text-align: center;\">\n<td style=\"height: 44.75px; text-align: center;\"><strong>校准器型号及编号</strong></td>\n<td style=\"height: 44.75px; text-align: center;\">cyyqxh</td>\n<td style=\"height: 44.75px; text-align: center;\"><strong>检测仪器型号及编号</strong></td>\n<td style=\"height: 44.75px; text-align: center;\" colspan=\"9\">cyyqbh</td>\n<td style=\"height: 44.75px; text-align: center;\"><strong>测量前</strong></td>\n<td style=\"height: 44.75px; text-align: center;\">&nbsp;</td>\n</tr>\n<tr style=\"height: 22.3906px; text-align: center;\">\n<td style=\"height: 22.3906px; text-align: center;\" colspan=\"12\"><strong>监测信息</strong></td>\n<td style=\"height: 22.3906px; text-align: center;\"><strong>测量后</strong></td>\n<td style=\"height: 22.3906px; text-align: center;\">&nbsp;</td>\n</tr>\n<tr style=\"height: 22.3906px; text-align: center;\">\n<td style=\"height: 67.1718px; text-align: center;\" rowspan=\"2\"><strong>测点编号</strong></td>\n<td style=\"height: 67.1718px; text-align: center;\" rowspan=\"2\"><strong>测点位置</strong></td>\n<td style=\"height: 67.1718px; text-align: center;\" rowspan=\"2\"><strong>风速（m/s）</strong></td>\n<td style=\"height: 22.3906px; text-align: center;\" colspan=\"2\"><strong>监测时间</strong></td>\n<td style=\"height: 22.3906px; text-align: center;\" colspan=\"6\"><strong>检测结果</strong></td>\n<td style=\"height: 22.3906px; text-align: center;\" colspan=\"3\"><strong>车流量统计（辆/小时）</strong></td>\n</tr>\n<tr style=\"height: 44.7812px;\">\n<td style=\"height: 44.7812px; text-align: center;\"><strong>开始时分</strong></td>\n<td style=\"height: 44.7812px; text-align: center;\"><strong>结束时分</strong></td>\n<td style=\"height: 44.7812px; text-align: center;\"><strong>L<sub>(A)</sub></strong></td>\n<td style=\"height: 44.7812px; text-align: center;\"><strong>L<sub>10</sub></strong></td>\n<td style=\"height: 44.7812px; text-align: center;\"><strong>L<sub>50</sub></strong></td>\n<td style=\"height: 44.7812px; text-align: center;\"><strong>L<sub>90</sub></strong></td>\n<td style=\"height: 44.7812px; text-align: center;\"><strong>L<sub>max</sub></strong></td>\n<td style=\"height: 44.7812px; text-align: center;\"><strong>L<sub>min</sub></strong></td>\n<td style=\"height: 44.7812px; text-align: center;\"><strong>中小型车</strong></td>\n<td style=\"height: 44.7812px; text-align: center;\"><strong>大型车</strong></td>\n<td style=\"height: 44.7812px; text-align: center;\"><strong>合计</strong></td>\n</tr>\n<tr style=\"height: 22.3906px; text-align: center;\">\n<td style=\"height: 22.3906px; text-align: center;\">{checkRes}</td>\n<td style=\"height: 22.3906px; text-align: center;\">{sampleDataValue}</td>\n<td style=\"height: 22.3906px; text-align: center;\">{other}</td>\n<td style=\"height: 22.3906px; text-align: center;\">{cyDate}</td>\n<td style=\"height: 22.3906px; text-align: center;\">{cyTime}</td>\n<td style=\"height: 22.3906px; text-align: center;\">{cyTime}</td>\n<td style=\"height: 22.3906px; text-align: center;\">{cyTime}</td>\n<td style=\"height: 22.3906px; text-align: center;\">&nbsp;</td>\n<td style=\"height: 22.3906px; text-align: center;\">&nbsp;</td>\n<td style=\"height: 22.3906px; text-align: center;\">&nbsp;</td>\n<td style=\"height: 22.3906px; text-align: center;\">&nbsp;</td>\n<td style=\"height: 22.3906px; text-align: center;\">&nbsp;</td>\n<td style=\"height: 22.3906px; text-align: center;\">&nbsp;</td>\n<td style=\"height: 22.3906px; text-align: center;\">&nbsp;</td>\n</tr>\n<tr style=\"height: 22.3906px;\">\n<td style=\"height: 22.3906px; text-align: center;\">{organId}</td>\n<td style=\"height: 22.3906px; text-align: center;\">{collectTime}</td>\n<td style=\"height: 22.3906px; text-align: center;\">{other}</td>\n<td style=\"height: 22.3906px; text-align: center;\">&nbsp;</td>\n<td style=\"height: 22.3906px; text-align: center;\">&nbsp;</td>\n<td style=\"height: 22.3906px; text-align: center;\">&nbsp;</td>\n<td style=\"height: 22.3906px; text-align: center;\">&nbsp;</td>\n<td style=\"height: 22.3906px; text-align: center;\">&nbsp;</td>\n<td style=\"height: 22.3906px; text-align: center;\">&nbsp;</td>\n<td style=\"height: 22.3906px; text-align: center;\">&nbsp;</td>\n<td style=\"height: 22.3906px; text-align: center;\">&nbsp;</td>\n<td style=\"height: 22.3906px; text-align: center;\">&nbsp;</td>\n<td style=\"height: 22.3906px; text-align: center;\">&nbsp;</td>\n<td style=\"height: 22.3906px; text-align: center;\">&nbsp;</td>\n</tr>\n<tr style=\"height: 22.3906px;\">\n<td style=\"height: 22.3906px; text-align: center;\">{reviewUserId}</td>\n<td style=\"height: 22.3906px; text-align: center;\">{bwxwd}</td>\n<td style=\"height: 22.3906px; text-align: center;\">{other}</td>\n<td style=\"height: 22.3906px; text-align: center;\">&nbsp;</td>\n<td style=\"height: 22.3906px; text-align: center;\">&nbsp;</td>\n<td style=\"height: 22.3906px; text-align: center;\">&nbsp;</td>\n<td style=\"height: 22.3906px; text-align: center;\">&nbsp;</td>\n<td style=\"height: 22.3906px; text-align: center;\">&nbsp;</td>\n<td style=\"height: 22.3906px; text-align: center;\">&nbsp;</td>\n<td style=\"height: 22.3906px; text-align: center;\">&nbsp;</td>\n<td style=\"height: 22.3906px; text-align: center;\">&nbsp;</td>\n<td style=\"height: 22.3906px; text-align: center;\">&nbsp;</td>\n<td style=\"height: 22.3906px; text-align: center;\">&nbsp;</td>\n<td style=\"height: 22.3906px; text-align: center;\">&nbsp;</td>\n</tr>\n<tr style=\"height: 22.3906px;\">\n<td style=\"height: 22.3906px; text-align: center;\">{bwxsfwz}</td>\n<td style=\"height: 22.3906px; text-align: center;\">{bwxwd}</td>\n<td style=\"height: 22.3906px; text-align: center;\">{other}</td>\n<td style=\"height: 22.3906px; text-align: center;\">&nbsp;</td>\n<td style=\"height: 22.3906px; text-align: center;\">&nbsp;</td>\n<td style=\"height: 22.3906px; text-align: center;\">&nbsp;</td>\n<td style=\"height: 22.3906px; text-align: center;\">&nbsp;</td>\n<td style=\"height: 22.3906px; text-align: center;\">&nbsp;</td>\n<td style=\"height: 22.3906px; text-align: center;\">&nbsp;</td>\n<td style=\"height: 22.3906px; text-align: center;\">&nbsp;</td>\n<td style=\"height: 22.3906px; text-align: center;\">&nbsp;</td>\n<td style=\"height: 22.3906px; text-align: center;\">&nbsp;</td>\n<td style=\"height: 22.3906px; text-align: center;\">&nbsp;</td>\n<td style=\"height: 22.3906px; text-align: center;\">&nbsp;</td>\n</tr>\n<tr style=\"height: 22.3906px;\">\n<td style=\"height: 22.3906px; text-align: center;\">{bwxsfwz}</td>\n<td style=\"height: 22.3906px; text-align: center;\">{specialNote}</td>\n<td style=\"height: 22.3906px; text-align: center;\">{other}</td>\n<td style=\"height: 22.3906px; text-align: center;\">&nbsp;</td>\n<td style=\"height: 22.3906px; text-align: center;\">&nbsp;</td>\n<td style=\"height: 22.3906px; text-align: center;\">&nbsp;</td>\n<td style=\"height: 22.3906px; text-align: center;\">&nbsp;</td>\n<td style=\"height: 22.3906px; text-align: center;\">&nbsp;</td>\n<td style=\"height: 22.3906px; text-align: center;\">&nbsp;</td>\n<td style=\"height: 22.3906px; text-align: center;\">&nbsp;</td>\n<td style=\"height: 22.3906px; text-align: center;\">&nbsp;</td>\n<td style=\"height: 22.3906px; text-align: center;\">&nbsp;</td>\n<td style=\"height: 22.3906px; text-align: center;\">&nbsp;</td>\n<td style=\"height: 22.3906px; text-align: center;\">&nbsp;</td>\n</tr>\n<tr style=\"height: 22.3906px;\">\n<td style=\"height: 22.3906px; text-align: center;\">{bwxsfwz}</td>\n<td style=\"height: 22.3906px; text-align: center;\">{secdClassName}</td>\n<td style=\"height: 22.3906px; text-align: center;\">{collectRemark}</td>\n<td style=\"height: 22.3906px; text-align: center;\">&nbsp;</td>\n<td style=\"height: 22.3906px; text-align: center;\">&nbsp;</td>\n<td style=\"height: 22.3906px; text-align: center;\">&nbsp;</td>\n<td style=\"height: 22.3906px; text-align: center;\">&nbsp;</td>\n<td style=\"height: 22.3906px; text-align: center;\">&nbsp;</td>\n<td style=\"height: 22.3906px; text-align: center;\">&nbsp;</td>\n<td style=\"height: 22.3906px; text-align: center;\">&nbsp;</td>\n<td style=\"height: 22.3906px; text-align: center;\">&nbsp;</td>\n<td style=\"height: 22.3906px; text-align: center;\">&nbsp;</td>\n<td style=\"height: 22.3906px; text-align: center;\">&nbsp;</td>\n<td style=\"height: 22.3906px; text-align: center;\">&nbsp;</td>\n</tr>\n</tbody>\n</table>\n<table style=\"border-collapse: collapse; width: 100%; margin-left: auto; margin-right: auto;\" border=\"1\"><colgroup><col style=\"width: 9.99181%;\"><col style=\"width: 9.99181%;\"><col style=\"width: 9.99181%;\"><col style=\"width: 9.99181%;\"><col style=\"width: 9.99181%;\"><col style=\"width: 9.99181%;\"><col style=\"width: 9.99181%;\"><col style=\"width: 9.99181%;\"><col style=\"width: 9.99181%;\"><col style=\"width: 9.99181%;\"></colgroup>\n<tbody>\n<tr>\n<td style=\"border-style: hidden;\">检测人：</td>\n<td style=\"border-style: hidden;\" colspan=\"4\">&nbsp;</td>\n<td style=\"border-style: hidden;\">审核人：</td>\n<td style=\"border-style: hidden;\" colspan=\"4\">&nbsp;</td>\n</tr>\n</tbody>\n</table>"'
        // const josns = `
        //         <table style="border-collapse: collapse; width: 100%; margin-left: auto; margin-right: auto;" border="1"><colgroup><col style="width: 9.99181%;"><col style="width: 9.99181%;"><col style="width: 9.99181%;"><col style="width: 9.99181%;"><col style="width: 9.99181%;"><col style="width: 9.99181%;"><col style="width: 9.99181%;"><col style="width: 9.99181%;"><col style="width: 9.99181%;"><col style="width: 9.99181%;"></colgroup>
        // <tbody>
        // <tr>
        // <td style="border-style: hidden;">检测人：</td>
        // <td style="border-style: hidden;" colspan="4">{wastewater1}</td>
        // <td style="border-style: hidden;" colspan="4">{wastewater2}</td>
        // <td style="border-style: hidden;" colspan="4">{wastewater}</td>
        // <td style="border-style: hidden;">审核人：</td>
        // <td style="border-style: hidden;" colspan="4">{collectRemark}</td>
        // </tr>
        // </tbody>
        // </table>`
        // htmlData = josns
        var reg = /\{(.*?)\}/gi
        var tmp = htmlData.match(reg)
        // console.log(tmp, 'tmp')

        // 数据数组（data）：
        // 通过接口得到数据对象（ key : keyVal ）
        // "如果此时keyVal是一个数组对象，"

        // 先获取到JSON，然后通过'{}'得到一个code数组循环i++
        // 当第 'i' 次同时找到这 'key' 在 'JSON' 中第 'i'

        // 次出现的地方将  '{code}' 替换成  'keyVal'

        // 当 数据数组
        // })
        this.$nextTick(() => {
        })
        // 获取到模板数据
        formConfigurationsServer.findFormConfiguration(data).then(ref => {
          // console.log(ref, 'ref')
          // const a = ref.result.records[0].checkRes.parseJSON()
          // const b = JSON.parse(ref.result.records[0].checkRes)
          // // console.log(JSON.parse(ref.result.records[0].collectDate), 1111)
          // 判断是否为数组
          // const a = Array.isArray(ref.result.records[0].specialNote)
          // console.log(a, 'a', ref.result.records[0].specialNote)
          // // 判断是否为对象
          // console.log(ref.result.records[0], '模板数据')
          // var str1 = str.replace('a', 'v');
          if (tmp) {
            for (var i = 0; i < tmp.length; i++) {
              let fillTxt = ''
              const a = tmp[i].replace(reg, '$1') // 是取tableData中的字段名字（ 不保留括号'{}')

              // console.log(a, 1111)
              // 如果key对应的keyVal有值
              if (ref.result[0][a]) {
              // console.log('key对应的keyVal有值')
              // 一对一  判断是对象、数组、string
                try {
                  // 为对象和数组的时候stringData为对象或者数组。无法转换时会走catch，但是不影响stringData原来的数据
                // console.log(JSON.parse(ref.result.records[0][a]), 333)
                  fillTxt = JSON.parse(ref.result[0][a])
                } catch (error) {
                  if (ref.result[0][a]) {
                    fillTxt = ref.result[0][a]
                  } else {
                    fillTxt = ''
                  }
                }
              } else { // 如果key对应的keyVal无值
              // console.log('key对应的keyVal无值')
              // 去 sampleDataValue 对应的字段中去查找（sampleDataValue保证有值，后期若无值情况 则需加判断,sampleDataValue是一个数组对象的JSON）
                var sampleDataValue = ''
                var factorDataVos = ''
                if (ref.result[0].sampleDataValue) {
                  sampleDataValue = JSON.parse(ref.result[0].sampleDataValue)
                } else {
                  sampleDataValue = ref.result[0].sampleData
                }
                // console.log(sampleDataValue, 'sampleDataValue')
                if (ref.result[0].factorDataVos) {
                  factorDataVos = ref.result[0].factorDataVos
                }
                try {
                // console.log(sampleDataValue[a], 'sampleDataValue[a]')
                  fillTxt = sampleDataValue[a].value[0].val
                } catch (error) {
                  // 如果不在 sampleDataValue 中，就去factorDataVos中匹配
                  try {
                    factorDataVos.map((item) => {
                      if (item.factorName == a) {
                        fillTxt = item.factorName
                      } else {
                        // JSON.parse(factorData)
                        fillTxt = ''
                      }
                    })
                  } catch (error) { fillTxt = '' }
                }
              // console.log(sampleDataValue, 'sampleDataValue')
              }

              htmlData = this.replaceIndex(htmlData, tmp[i], 0, fillTxt)
            // console.log(htmlData)
            // const a = tmp[i].replace(reg, '$1')
            // // console.log(a)
            // // console.log(ref.result.records[0][a], 1111)
            // let fillTxt = ''
            // try {
            //   // 为对象和数组的时候stringData为对象或者数组。无法转换时会走catch，但是不影响stringData原来的数据
            //   console.log(JSON.parse(ref.result.records[0][a]), 333)
            //   fillTxt = JSON.parse(ref.result.records[0].sampleDataValue)
            //   console.log(fillTxt, 'fillTxt')
            // } catch (error) {
            //   if (ref.result.records[0][a]) {
            //     fillTxt = ref.result.records[0][a]
            //     // console.log(fillTxt, 222, 'isString')
            //   } else {
            //     fillTxt = ''
            //   }
            // }
            // this.replaceIndex(josns, tmp[i], i, fillTxt)
            // console.log(this.replaceIndex(josns, tmp[i], i, fillTxt))
            // console.log(tmp[i]) // 保留括号
              // console.log(tmp[i].replace(reg, '$1')) // 不保留括号
            }
            // const base64 = s => window.btoa(unescape(encodeURIComponent(s)))

            this.$nextTick(() => {
            // window.location.href = 'data:application/msword;base64,' + base64(htmlData)
              const blob = new Blob([htmlData], {
                type: 'application/msword'
              })
              // 返回一个新创建的 Blob 对象，其内容由参数中给定的数组串联组成。
              const objectUrl = URL.createObjectURL(blob)
              const link = document.createElement('a')
              link.href = objectUrl
              const fName = '采样记录单下载'
              link.setAttribute('download', fName)
              // 下载文件名
              document.body.appendChild(link)
              link.click()
            })
          } else {
            alert('no match.')
          }
          // const arr = [1, 2]
          // console.log(ref.result.records[0])
          // const stringData = ref.result.records[0].collectRemark

        // console.log(ref.result.records[0].sampleDataValue instanceof Object)
        // try {
        //   // 为对象和数组的时候stringData为对象或者数组。无法转换时会走catch，但是不影响stringData原来的数据。
        //   arr = JSON.parse(arr)
        //   console.log(arr, 333)
        //   return true
        // } catch (error) {
        //   console.log(stringData, 222, 'isString')
        //   return false
        // }
        // console.log(ref.result.records[0].sampleDataValue, '1')
        // console.log(this.isString(ref.result.records[0].sampleDataValue), 1)
        // console.log(this.isObject(ref.result.records[0].sampleDataValue), 2)
        // console.log(this.isArray(ref.result.records[0].sampleDataValue), 3)
        // console.log(ref.result.records[0].specialNote, 'specialNote')
        // console.log(JSON.parse(ref.result.records[0].sampleDataValue), 1111)
        })
      })
      // if (this.recordForm.taskId && this.recordForm.secClassId) {
      //   const url = '/api/word/downSampleRecordByTaskIdAndSecdClassId?taskId=' + this.recordForm.taskId + '&secdClassId=' + this.recordForm.secClassId
      //   window.open(url)
      // } else {
      //   this.$message.warning('检测类别不能为空')
      // }
    },
    // 替换匹配位置的文本
    // str 待处理字符串
    // cha 需替换的字符
    // num 替换的位置 从 i = 0 开始
    // fillTxt 替换的字符
    replaceIndex(str, cha, num, fillTxt) {
      console.log(cha, num, 77777)
      console.log([...str.matchAll(new RegExp(cha, 'g'))], 6666)
      console.log([...str.matchAll(new RegExp(cha, 'g'))][num], 5555)
      var s = [...str.matchAll(new RegExp(cha, 'g'))][num]
      return (
        s.input.substring(0, s.index) +
        fillTxt +
        s.input.substring(s.index + cha.length)
      )
    },
    goBack() {
      this.$router.go(-1)
    }
  }
}
</script>

<style scoped lang="scss" type="text/scss">
.codeInput /deep/.el-input__inner{
  //  border: 1px solid #1890ff;
  background: #ecf3fc!important;;

}
/deep/.el-table__header-wrapper /deep/.el-checkbox{

display:none!important

}
  /deep/.el-table__body td {
    overflow: hidden;
  }
  .search_div {
    >div {
      &:nth-child(1){
        margin-right: 10px;
      }
      display: inline-block;
    }
  }

  .search_input {
    width: 200px;
    margin-bottom: 5px;
  }
  .search-right {
    text-align: right;
    padding-right: 25px;
  }
  .item {
    font-size: 16px;
  }
  ::v-deep .el-card .el-card__header {
    padding: 5px 20px;
    background: #F3F2F2;
  }
  .info-table-new {
    font-size: 14px;
    width: 100%;
    text-align: center;
    margin-top: 10px;
    border-top: 1px solid #ececec;
    border-left: 1px solid #ececec;
    line-height: 35px;
    td {
      border-bottom: 1px solid #ececec;
      border-right: 1px solid #ececec;
      width: 25%;
      height: 35px;
      // &:nth-child(2n + 1) {
      //   width: 25%;
      //   background: #f5f5f5;
      // }
    }
  }

  .demo-image__lazy {
    display: flex;
    overflow-y: auto;
  }
  .demo-image__lazy .el-image {
    display: block;
    max-height: 300px;
    width: 100%;
    margin-bottom: 10px;
  }
</style>

<style scoped lang="scss" type="text/scss">
  .search_div {
    >div {
      &:nth-child(1){
        margin-right: 10px;
      }
      display: inline-block;
    }
  }

  .search_input {
    width: 200px;
    margin-bottom: 5px;
  }
  .search-right {
    text-align: right;
    padding-right: 25px;
  }
  .item {
    font-size: 16px;
  }
  ::v-deep .el-card .el-card__header {
    padding: 5px 20px;
    background: #F3F2F2;
  }
  .block-flex {
    position: relative;
    display: flex;
    &>div{
      border: 1px solid #B7B7B7;
      width: 100px;
      margin: 0;
      line-height: 30px;
      text-align: center;
    }
    &>div:first-child {
      background: #B7B7B7;
    }
  }
  .card-left {
    width: 100%;
    min-height: 200px;
    max-height: 518px;
  }
  .card-right {
    width: 100%;
    min-height: 200px;
    max-height: 400px;
  }
  .el-card {
    overflow: auto;
  }
  .el-dropdown-link {
    cursor: pointer;
    color: #409EFF;
  }
  .el-icon-arrow-down {
    font-size: 12px;
  }

  /deep/ .el-input.is-disabled .el-input__inner {
    color:unset
  }
  .clearfix {
    line-height: 40px;
    display: flex;
  }
  .apostrophe{
    text-overflow: ellipsis;
    overflow: hidden;
    white-space: nowrap;
  }
</style>
